<template>
  <div id="app">
    <header>
      <a v-if="isBack" @click="GoBack" class="page-back router-link-active">
        <i class="mintui mintui-back"></i>
      </a>
      <span>{{header}}</span>
    </header>
    <router-view/>

  </div>
</template>

<script>
  import {
    Toast
  } from 'mint-ui';
  export default {
    name: 'app',
    data() {
      return {

      }
    },
    computed: {
      header() {
        return this.$route.meta.header
      },
      isBack() {
        return this.$route.meta.isBack
      }
    },
    mounted() {
      if (!sessionStorage.getItem('loginData')) this.$router.push('/login');
      var that = this;
      document.addEventListener('plusready', function () {
        plus.key.addEventListener('backbutton', function () {

          if (that.$route.name != "home" && that.$route.name != "mine" && that.$route.name != "notice" && that.$route
            .name != "login") {
            window.history.go(-1);
          } else {
            //webview.close(); //hide,quit
            //plus.runtime.quit();
            //首页返回键处理
            //处理逻辑：1秒内，连续两次按返回键，则退出应用；
            var first = null;
            plus.key.addEventListener('backbutton', function () {
              //首次按键，提示‘再按一次退出应用’
              if (!first) {
                first = new Date().getTime();
                Toast({
                  message: '再按一次退出应用!',
                  position: 'top',
                  duration: 2000
                });
                setTimeout(function () {
                  first = null;
                }, 2000);
              } else {
                if (new Date().getTime() - first < 2000) {
                  plus.runtime.quit();
                }
              }
            }, false);
          }

        });
      });
    },
    watch: {
      $route(curVal, from) {
        this.backSrc = from.path;
        window.onscroll = null;
      }
    },
    methods: {
      GoBack: function () {
        if (window.history.length >= 1) {
          this.$router.back(-1)
        } else {
          this.$router.push('/home')
        }
      }
    }
  }

</script>

<style scoped>
  #app i {
    color: #fff
  }

</style>
<style>
  body,
  html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
  }

  * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }

  #app {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    font-size: .3rem;
    height: 100%;
    width: 100%;
  }
  .button_wrap button:disabled{
    opacity: 0.4;
  }
  header {
    background: #3B8CE7;
    color: white;
    font-size: 0.48rem;
    height: 1.2rem;
    line-height: 1.3rem;
    position: relative;
  }

  .page-back {
    font-size: 0.6rem;
    position: absolute;
    left: 0.4rem;
    text-decoration: none;
    color: black;
  }

  a {
    color: inherit;
    text-decoration: none;
  }
li{
  list-style: none
}
.wrap .top .bottom {
    display: flex;
    justify-content: space-between
  }
</style>
<style>
  .mint-button--primary{
    background: #3B8CE7
  }
</style>